<?php

class Payments extends TPage
{
	public $payment_manager;
	public $element_manager;
	public $currency = null;
	
	public function onLoad($params)
	{
		parent::onLoad($params);
		
		$this->payment_manager = $this->Application->Modules['payments'];	
		$this->PaymentList->DataSource = $this->payment_manager->getPaymentsList();
		$this->PaymentList->dataBind();
		
		$this->element_manager = $this->Application->Modules['plan_elements'];
		$all_plan_elements = $this->element_manager->getPlanElementsListByUserId($this->User->getName());
		
		$plan_elements_with_price = array();
		$total_price = 0;
		foreach($all_plan_elements as $element)
			if($element->getPrice() != null)
			{
				$plan_elements_with_price[] = $element;
				$total_price += $element->getPrice();
			}
		$this->PlanElementPaymentList->DataSource = $plan_elements_with_price;
		$this->PlanElementPaymentList->dataBind();
		
		$setting_manager = $this->Application->Modules['settings'];
		if($setting = $setting_manager->getSettingByName(SettingManager::$CURRENCY_NAME))
			$this->currency = $setting->getValue();
			
		$this->total_price_label->Text = $this->getValueWithCurrency($total_price);
	}
	
	public function getCurrencyName()
	{
		if($this->currency == null)
			return $this->currency;
		return '-';
	}
	
	public function getValueWithCurrency($value)
	{
		if($this->currency != null)
		{
			$value = $value.' '.$this->currency;
		}
		return $value;
	}
}

?>